﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DA
{
    public class DanhMucPhong_DA
    {
        QLKhachSanDataContext KHDA;

        public List<DanhMucPhong> TimKiemPhongTheoMa(string tim)
        {
            try
            {
                KHDA = new QLKhachSanDataContext();
                return KHDA.DanhMucPhongs.Where(p => p.MaLoai.Contains(tim)).ToList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                KHDA.Dispose();
            }
        }
        //public List<DanhMucPhong> TimKiemKHTheoTen(string tim)
        //{
        //    try
        //    {
        //        KHDA = new QLKhachSanDataContext();
        //        return KHDA.KhachHangs.Where(p => p.TenKH.Contains(tim) || p.TenKH.Contains(tim)).ToList();
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }
        //    finally
        //    {
        //        KHDA.Dispose();
        //    }
        //}
        public List<DanhMucPhong> LayDSPhong()
        {
            try
            {
                KHDA = new QLKhachSanDataContext();
                return KHDA.DanhMucPhongs.ToList();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                KHDA.Dispose();
            }
        }
        public bool ThemPhong(DanhMucPhong K)
        {
            try
            {
                KHDA = new QLKhachSanDataContext();
                DanhMucPhong s = new DanhMucPhong();
                s.MaLoai = K.MaLoai;
                s.TenLoai = K.TenLoai;
                s.SoLuong = K.SoLuong;
                s.DonGia = K.DonGia;
                s.SoLuongKhach = K.SoLuongKhach;
                s.GhiChu = K.GhiChu;
                KHDA.DanhMucPhongs.InsertOnSubmit(s);
                KHDA.SubmitChanges();
                return true;

            }
            catch
            {
                return false;
            }
            finally
            {
                KHDA.Dispose();
            }
        }
        public bool SuaPhong(DanhMucPhong K)
        {
            try
            {
                KHDA = new QLKhachSanDataContext();
                DanhMucPhong s = KHDA.DanhMucPhongs.Where(p => p.MaLoai == K.MaLoai).FirstOrDefault();
                s.SoLuong = K.SoLuong;
                s.DonGia = K.DonGia;
                s.SoLuongKhach = K.SoLuongKhach;
                s.GhiChu = K.GhiChu;
                KHDA.SubmitChanges();
                return true;

            }
            catch
            {
                return false;
            }
            finally
            {
                KHDA.Dispose();
            }
        }
        public bool XoaPhong(string ma)
        {
            try
            {
                KHDA = new QLKhachSanDataContext();
                DanhMucPhong s = KHDA.DanhMucPhongs.Where(p => p.MaLoai == ma).FirstOrDefault();
                KHDA.DanhMucPhongs.DeleteOnSubmit(s);
                KHDA.SubmitChanges();
                return true;

            }
            catch
            {
                return false;
            }
            finally
            {
                KHDA.Dispose();
            }
        }
        public double LayDongiaPhongTheoMa(string ma)
        {
            try
            {
                KHDA = new QLKhachSanDataContext();
                return KHDA.DanhMucPhongs.Where(p=>p.MaLoai==ma).Select(p=>p.DonGia.Value).FirstOrDefault();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                KHDA.Dispose();
            }
        }
    }
}
